<?php include("common/conn.php"); 

// 获取规格 
if ($_REQUEST[act] == 'getGuige') {
	if ($_REQUEST[shopid] != '') {
		$query = mysql_query("select * from select_model where ziid =(select id from zifenlei where fenleiid=(select leimu from shop where shopid=".$_REQUEST[shopid].") limit 1)");
	}elseif ($_REQUEST[zixilie] != '') {
		$query = mysql_query("select * from select_model where ziid =".$_REQUEST[zixilie]);
	}
	while ($row = mysql_fetch_assoc($query)) {
		$select_model[] = $row;
	}
	foreach ($select_model as $k => $v) {
		$select[$k][name] = $v[fTitle];
		if ($v[sTitle]!='') {
			$select[$k][classs][name] = $v[sTitle];
			$select[$k][classs][num] = $v[number];
			$select[$k][classs][price] = $v[price];
		}else{
			$select[$k][num] = $v[number];
			$select[$k][price] = $v[price];	
		}
	}
	$fTitle = array();
	foreach ($select as $k => $v) {
		$fTitle[$k] = $v[name];
	}
	$fTitle_key = array();
	foreach ($fTitle as $k => $v) {
		$fTitle_key[$v][] = $k;
	}
	$data = array();
	foreach ($fTitle_key as $k => $v) {
		foreach ($select as $key => $value) {
			if ($k == $value[name]) {
				$data[$k][name] = $value[name];
				if ($value[classs]!='') {
					$data[$k][classs][] = $value[classs];
				}else{
					$data[$k][num] = $value[num];
					$data[$k][price] = $value[price];
					$data[$k][classs] = array();
				}
			}
		}
	}
	echo json_encode($data);
	exit();
}
// 获取规格 end

// 根据子分类获取子分类类型(海淘或快购)
if ($_REQUEST[act] == 'getType' && isset($_REQUEST[zixilie])) {
	$query = mysql_query("select * from zifenlei where id=".$_REQUEST[zixilie]);
	$zixilie = mysql_fetch_assoc($query);
	echo $zixilie[type];
	exit;
}
// 根据子分类获取子分类类型(海淘或快购) end

// 根据商家获取子分类类型(海淘或快购)
if ($_REQUEST[act] == 'getType' && isset($_REQUEST[shopid])) {
	$query = mysql_query("select * from zifenlei where fenleiid=(select leimu from shop where shopid='".$_REQUEST[shopid]."') limit 1");
	$zixilie = mysql_fetch_assoc($query);
	echo $zixilie[type];
	exit;
}
// 根据商家获取子分类类型(海淘或快购) end

// 查询goodselect表数据
if (!empty($_REQUEST[gid])) {
	$query = mysql_query("select * from goodsselect where goodsid = ".$_REQUEST[gid]);
	while ($row = mysql_fetch_assoc($query)) {
		$goodsselect[] = $row;
	}
	foreach ($goodsselect as $k => $v) {
		$select[$k][name] = $v[fTitle];
		if ($v[sTitle]!='') {
			$select[$k][classs][name] = $v[sTitle];
			$select[$k][classs][num] = $v[number];
			$select[$k][classs][price] = $v[price];				
		}else{
			$select[$k][num] = $v[number];
			$select[$k][price] = $v[price];	
		}
	}
	$fTitle = array();
	foreach ($select as $k => $v) {
		$fTitle[$k] = $v[name];
	}
	$fTitle_key = array();
	foreach ($fTitle as $k => $v) {
		$fTitle_key[$v][] = $k;
	}
	$data = array();
	foreach ($fTitle_key as $k => $v) {
		foreach ($select as $key => $value) {
			if ($k == $value[name]) {
				$data[$k][name] = $value[name];
				if ($value[classs]!='') {
					$data[$k][classs][] = $value[classs];
				}else{
					$data[$k][num] = $value[num];
					$data[$k][price] = $value[price];
					$data[$k][classs] = array();
				}
			}
		}
	}
}else{
	$query = mysql_query("select * from select_model where ziid = (select id from zifenlei where fenleiid=(select leimu from shop limit 1) limit 1)");
	while ($row = mysql_fetch_assoc($query)) {
		$select_model[] = $row;
	}
	foreach ($select_model as $k => $v) {
		$select[$k][name] = $v[fTitle];
		if ($v[sTitle]!='') {
			$select[$k][classs][name] = $v[sTitle];
			$select[$k][classs][num] = $v[number];
			$select[$k][classs][price] = $v[price];				
		}else{
			$select[$k][num] = $v[number];
			$select[$k][price] = $v[price];	
		}
	}
	$fTitle = array();
	foreach ($select as $k => $v) {
		$fTitle[$k] = $v[name];
	}
	$fTitle_key = array();
	foreach ($fTitle as $k => $v) {
		$fTitle_key[$v][] = $k;
	}
	$data = array();
	foreach ($fTitle_key as $k => $v) {
		foreach ($select as $key => $value) {
			if ($k == $value[name]) {
				$data[$k][name] = $value[name];
				if ($value[classs]!='') {
					$data[$k][classs][] = $value[classs];
				}else{
					$data[$k][num] = $value[num];
					$data[$k][price] = $value[price];
					$data[$k][classs] = array();
				}
			}
		}
	}
}

// 查询goodselect表数据 end

if($_GET['gid']!=""){
	$rert30=mysql_query("select * from goods where goodsid='".$_GET['gid']."'");
	$sdg30=mysql_fetch_array($rert30);
	// 判断该商品是否有配送时间
	$query = mysql_query("select * from zifenlei where id=".$sdg30[zixilie]);
	$zixilie = mysql_fetch_assoc($query);
	$hasDeliveryTime = $zixilie[type];
	// 判断该商品是否有配送时间 end
}
$citysql=mysql_query("select * from city");
if ($_REQUEST[act]=='selectcat') {
	$query = mysql_query("select zileimu from shop where shopid=".$_REQUEST[shopid]);
	$shop = mysql_fetch_assoc($query);
	$query1=mysql_query("select * from zifenlei where id in (".$shop['zileimu'].")");
	$arr = array();
	$i=0;
	if ($_REQUEST[gid]!='') {
		$query=mysql_query("select * from goods where goodsid='".$_REQUEST[gid]."'");
		$goods=mysql_fetch_array($query);
		while ($row=mysql_fetch_array($query1)) {
			$arr[$i][id]=$row[id];
			if ($row[type] == 0) {
				$arr[$i][name]=$row[name]."(海淘)";
			}elseif ($row[type] == 1) {
				$arr[$i][name]=$row[name]."(快购)";
			}
			
			if ($goods[zixilie]==$row[id]) {
				$arr[$i][select]='true';
			}else{
				$arr[$i][select]='false';
			}
			$i++;
		}
	}else{
		while ($row=mysql_fetch_array($query1)) {
			$arr[$i][id]=$row[id];
			if ($row[type] == 0) {
				$arr[$i][name]=$row[name]."(海淘)";
			}elseif ($row[type] == 1) {
				$arr[$i][name]=$row[name]."(快购)";
			}
			$i++;
		}
	}


	$query2=mysql_query("select id,name from fareml where shopid='".$_REQUEST[shopid]."'  or shopid = 0");
	$arr1 = array();
	$i=0;
	while ($row = mysql_fetch_assoc($query2)) {
		$arr1[] = $row;
	}
	$array = array('cats' => $arr,'fare' => $arr1 );
	echo json_encode($array);
	exit();
}
// 添加规格
if (!empty($_GET[data])) {
	$data = json_decode($_GET[data],true);
	$query = mysql_query("DELETE from goodsselect where goodsid = ".$data[0][goodsid]);
	$fSum = count($data);
	for ($i=0; $i < $fSum; $i++) {
		if (isset($data[$i][classs])) {
			$classs = $data[$i][classs];
			$sSum = count($classs);
			for ($j=0; $j < $sSum; $j++) { 
				$query=mysql_query("INSERT INTO goodsselect(goodsid,fTitle,sTitle,price,`number`) VALUES ('".$data[$i][goodsid]."','".$data[$i][name]."','".$classs[$j][name]."','".$classs[$j][price]."','".$classs[$j][num]."')");
			}
		}else{
			$query=mysql_query("INSERT INTO goodsselect(goodsid,fTitle,price,`number`) VALUES ('".$data[$i][goodsid]."','".$data[$i][name]."','".$data[$i][price]."','".$data[$i][num]."')");
		}
	}
	// 统计商品总数 
	$query= mysql_query("select sum(number) as sum from goodsselect where goodsid=".$data[0][goodsid]);
	$goodsselect = mysql_fetch_assoc($query);
	$goods_number = $goodsselect['sum'];
	$query = mysql_query("UPDATE goods set `number`=".$goods_number." where goodsid=".$data[0][goodsid]);
	// 统计商品总数 end
	exit;
}
// 添加规格 end
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link href="css/styles.css" type="text/css"/>
	<title>e网批发管理后台</title>
	<link href="css/styles.css" rel="stylesheet" type="text/css" />
	<link href="css/style2.css" rel="stylesheet" type="text/css" />
	<style type="text/css">
		.cy_mode{position: relative;left:0px; width:100%;  text-align:left; line-height:30px; margin-top:5px; border:0px;   overflow:hidden; padding-bottom:10px;}
		.indexfloat{ position:relative;float:left; margin-left:0px; margin-top:0px;}
		.indexfloat input{
			margin-top: 20px;
		}
		.zi td {
			position:relative;
			left:220px;
		}
		ol,
	    ul {
	        list-style: none;
	    }
	    
	    #class>li {
	        padding: 5px 10px;
	        border-bottom: 1px solid #999
	    }
	    
	    #class>li ul {
	        margin: 10px 80px;
	    }
	    
	    #class>li span {
	        margin: 0 10px;
	    }
	    
	    #class >li ul li {
	        line-height: 40px;
	    }
	</style>
	<?php 

	if($_GET['action']=="ok")
	{ 

		if($_GET[shopid]!="")
		{
			$shopid=$_GET[shopid];
		}
		else
		{
			$shopid=$_POST[shopid];
		}
		$rert31=mysql_query("select *from shop where shopid='".$shopid."'");
		$rowf1=mysql_fetch_array($rert31);
		$xilie=$rowf1[leimu];
		$sql = "INSERT INTO goods(title,shangjia,price,summary,xilie,zixilie,yuanjia,shopid,delivery_time,can_fanquan,muid,start_num,start_num_desc,Freight_dir) VALUES ('$_REQUEST[title]','$_REQUEST[shangjia]','$_REQUEST[price]','$_REQUEST[summary]','$xilie','$_REQUEST[zixilie]','$_REQUEST[yuanjia]','$shopid','$_REQUEST[delivery_time]','$_REQUEST[can_fanquan]','$_REQUEST[muid]','$_REQUEST[start_num]','$_REQUEST[start_num_desc]','$_REQUEST[Freight_dir]')";
		echo $sql;
		
		$srat = mysql_query($sql);
		// var_dump($srat);die;
		$g = mysql_insert_id();
		$query = mysql_query("UPDATE goodsselect set goodsid = ".$g." where goodsid = 0");

		// 统计商品数量
		$query= mysql_query("select sum(number) as sum from goodsselect where goodsid=".$g);
		$goodsselect = mysql_fetch_assoc($query);
		$goods_number = $goodsselect['sum'];
		$query = mysql_query("UPDATE goods set `number`=".$goods_number." where goodsid=".$g);
		// 统计商品数量 end

		$srat = mysql_query("INSERT INTO coupon(goodsid,shopid) VALUES ('$g','$shopid')");
		echo "<script>alert('添加成功');window.location.href='addgoodsimg.php?id=$g';</script>";
	}
	if($_GET['ch']=="ok"){

		if($_GET[shopid]!=""){
			$shopid=$_GET[shopid];
		}
		else{
			$shopid=$_POST[shopid];
		}
		$rert34=mysql_query("select *from shop where shopid='".$shopid."'");
		$rowf4=mysql_fetch_array($rert34);
		$xilie=$rowf4[leimu];
		// $content = addslashes($_POST['content']);
		$sql = "update goods set start_num_desc='".$_POST['start_num_desc']."',title='".$_POST['title']."',shangjia='".$_POST['shangjia']."',price='".$_POST['price']."',shopid='".$_POST['shopid']."',yuanjia='".$_POST['yuanjia']."',xilie='".$xilie."',zixilie='".$_POST['zixilie']."',summary='".$_POST['summary']."',delivery_time='".$_POST['delivery_time']."',Freight_dir='".$_POST['Freight_dir']."',can_fanquan='".$_POST['can_fanquan']."',muid='".$_POST['muid']."',start_num='".$_POST['start_num']."' where goodsid='".$_REQUEST['gid']."'";
		$srat1=mysql_query($sql);

		echo "<script>alert('更新成功');window.location.href='goods2.php?shopid=$_GET[shopid]';</script>";
	}
	if($_GET[del]=="ok")
	{
		$srat1=mysql_query("DELETE FROM goodsselect where selectid='".$_REQUEST['gid']."'");
	}

	// 查询商家的运费模板
	if ($_GET['gid'] != '') {
		$where_fare = 'where shopid = (select shopid from goods where goodsid = '.$_GET['gid'].') or shopid = 0';
	}else{
		$where_fare = 'where shopid = (select shopid from shop limit 1) or shopid = 0';
	}
	$query = mysql_query("select id,name from fareml ".$where_fare);
	while ($row = mysql_fetch_assoc($query)) {
		$fareml[] = $row;
	}
	// 查询商家的运费模板
	?>
	<script type="text/javascript" src="./js/jquery.js"></script>
	<script type="text/javascript" src="js/jquery.validate.js"></script>
	<script type="text/javascript" src="js/addgoods.js"></script>
	<script>

		var maxstrlen=1500;

		function Q(s){return document.getElementById(s);}

		function checkWord(c){

			len=maxstrlen;

			var str = c.value;

			myLen=getStrleng(str);

			var wck=Q("wordCheck");

			if(myLen>len*2){

				c.value=str.substring(0,i+1);

			}

			else{

				wck.innerHTML = Math.floor((len*2-myLen)/2);

			}

		}

		function getStrleng(str){

			myLen =0;

			i=0;

			for(;(i<str.length)&&(myLen<=maxstrlen*2);i++){

				if(str.charCodeAt(i)>0&&str.charCodeAt(i)<128)

					myLen++;

				else

					myLen+=2;

			}

			return myLen;

		}



	</script>

	<link rel="stylesheet" href="write/themes/default/default.css" />
	<script charset="utf-8" src="write/kindeditor-min.js"></script>
	<script charset="utf-8" src="write/lang/zh_CN.js"></script>
	<script>
		var editor;
		KindEditor.ready(function(K) {
			editor = K.create('textarea[id="content"]', {
				allowFileManager : true
			});
			K('input[name=getHtml]').click(function(e) {
				alert(editor.html());
			});
			K('input[name=isEmpty]').click(function(e) {
				alert(editor.isEmpty());
			});
			K('input[name=getText]').click(function(e) {
				alert(editor.text());
			});
			K('input[name=selectedHtml]').click(function(e) {
				alert(editor.selectedHtml());
			});
			K('input[name=setHtml]').click(function(e) {
				editor.html('<h3>Hello KindEditor</h3>');
			});
			K('input[name=setText]').click(function(e) {
				editor.text('<h3>Hello KindEditor</h3>');
			});
			K('input[name=insertHtml]').click(function(e) {
				editor.insertHtml('<strong>插入HTML</strong>');
			});
			K('input[name=appendHtml]').click(function(e) {
				editor.appendHtml('<strong>添加HTML</strong>');
			});
			K('input[name=clear]').click(function(e) {
				editor.html('');
			});
		});


	</script>
</head>

<body>

	<!--header-->
	<?php include("common/header.php");?>
	<!--header end-->

<div style="margin-bottom:150px;">
	<form action="?<?php if($_GET['gid']!=""){echo "ch=ok";}else{echo "action=ok";} ?>&shopid=<?php echo $_REQUEST[shopid]; ?>&gid=<?php echo $_REQUEST[gid]; ?>" method="post" id="form" enctype="multipart/form-data"> 	

		<!--收货信息-->
		<div class="car_mode">

			<div class="indexfloat" style="width:15%; margin-left:5%;">
				商品名称
			</div> 

			<div class="indexfloat" style="width:79%;">

				<input class="text required"  name="title" type="text" placeholder="商品标题"  style="width: 400px;" value="<?php echo $sdg30[title];?>"/> 

			</div>

		</div>
		<!--收货信息 end-->

		<!--是否上架-->
		<div class="car_mode">

			<div class="indexfloat" style="width:15%; margin-left:5%;">
				是否上架
			</div> 


			<div class="indexfloat" style="width:79%;">

				<?php if (!isset($_REQUEST[gid])) { ?>
				<input type="radio" name="shangjia" value="1" checked>是
				<input type="radio" name="shangjia" value="0">否					
				<?php }else{ ?>
				<input type="radio" name="shangjia" value="1" <?php if ($sdg30[shangjia]==1) { ?>checked<?php } ?>>是
				<input type="radio" name="shangjia" value="0" <?php if ($sdg30[shangjia]==0) { ?>checked<?php } ?>>否
				<?php } ?>
			</div>

		</div>
		<!--是否上架 end-->



		<!--收货信息-->
		<div class="car_mode">

			<div class="indexfloat" style="width:15%; margin-left:5%;">
				价格
			</div> 

			<div class="indexfloat" style="width:79%;">
				<?php if($_SESSION['type'] == 0) {?>
					<input class="text required"  name="price" type="text" placeholder="商品销售价格" value="<?php echo $sdg30[price];?>"/> 
				<?php } else {?>
					<input class="text required"  name="price" type="text" onclick="tanchu()" readonly="disabled" placeholder="商品销售价格" value="<?php echo $sdg30[price];?>"/> 
				<?php }?>
			</div>

		</div>
		<!--收货信息 end-->	
		<!--收货信息-->
		<div class="car_mode">
			<div class="indexfloat" style="width:15%; margin-left:5%;">
				原价
			</div> 
			<div class="indexfloat" style="width:79%;">
				<?php if($_SESSION['type'] == 0) {?>
					<input class="text required"  name="yuanjia" type="text" placeholder="商品市场价格" value="<?php echo $sdg30[yuanjia];?>"/> 
				<?php } else {?>
					<input class="text required"  name="yuanjia" onclick="tanchu()" type="text" readonly="disabled" placeholder="商品市场价格" value="<?php echo $sdg30[yuanjia];?>"/> 
				<?php }?>
			</div>
		</div>
		<!--收货信息 end-->

		<!--收货信息-->
		<div class="car_mode">

			<div class="indexfloat" style="width:15%; margin-left:5%;">
				起批量
			</div> 

			<div class="indexfloat" style="width:33%;">

				<input class="text required"  name="start_num" type="text" placeholder="起批量(数字)" value="<?php echo $sdg30[start_num];?>"/> 

				<input class="text required"  name="start_num_desc" type="text" placeholder="描述(文字)" value="<?php echo $sdg30[start_num_desc];?>"/> 

			</div>

		</div>
		<!--收货信息 end-->

		<!--收货信息-->
		<div class="car_mode">

			<div class="indexfloat" style="width:15%; margin-left:5%;">
				简介
			</div> 

			<div class="indexfloat" style="width:79%;">
				<textarea name="summary" cols="20" class="required" rows="5"><?php echo $sdg30[summary];?></textarea>

			</div>

		</div>
		<!--收货信息 end-->
		<div class="car_mode"   style="display:none">

			<div class="indexfloat" style="width:15%; margin-left:5%;">
				运费说明
			</div> 

			<div class="indexfloat" style="width:79%;">
				<textarea name="Freight_dir" cols="20"  rows="5"><?php echo $sdg30[Freight_dir];?></textarea>
			</div>

		</div>
		
		<div class="car_mode"   style="display:none;">

			<div class="indexfloat" style="width:15%; margin-left:5%;">
				商品详情
			</div> 

			<div class="indexfloat" style="width:79%;">

				<textarea name="content" id="content" style="width:100%;height:400px;"><?php echo $sdg30[content];?></textarea>

			</div>

		</div>

		<div class="car_mode">

			<div class="indexfloat" style="width:15%; margin-left:5%;">
				商家
			</div> 
			<div class="indexfloat" style="width:79%;margin-top:25px;">
				<?php if ($_REQUEST[shopid]=='') { ?>
				<select name="shopid" class="shopid select">
					<?php
					if ($_REQUEST[gid]!='') {
						$query=mysql_query("select * from goods where goodsid='".$_REQUEST[gid]."'");
						$goods=mysql_fetch_array($query);
					}
					$query=mysql_query("select * from shop");
					while ($row=mysql_fetch_array($query)) { ?>
					<option value="<?php echo $row[shopid]; ?>" <?php if($goods[shopid]==$row[shopid]){ ?> selected <?php } ?>>
						<?php echo $row[name]; ?>
					</option>
					<?php } ?>
				</select>
				<?php }else{

					$query=mysql_query("select * from shop where shopid='".$_REQUEST[shopid]."'");
					$row=mysql_fetch_array($query);
					?>

					<input type="text" value="<?php echo $row[name]; ?>" readonly>
					<input type="hidden" name="shopid" value="<?php echo $_REQUEST[shopid]; ?>">
					<?php } ?>							
				</div>

		</div>
		<!-- 商家 end -->

			<!--收货信息-->
			<div class="car_mode">

				<div class="indexfloat" style="width:15%; margin-left:5%;">
					运费模板
				</div> 

				<div class="indexfloat" style="width:79%;margin-top:25px;">

					<select name="muid" id="fare">
						<?php foreach ($fareml as $v) { ?>
						<option value="<?php echo $v[id]; ?>" <?php if ($v[id] == $sdg30[muid] ) { ?> selected <?php } ?> ><?php echo $v['name']; ?></option>
						<?php } ?>
					</select>

				</div>

			</div>
			<!--收货信息 end-->

			<input type="hidden" id="gid" value="<?php echo $_REQUEST[gid]; ?>">
			<!--子分类-->
			<div class="car_mode">

				<div class="indexfloat" style="width:15%; margin-left:5%;">
					子分类
				</div> 

				<div class="indexfloat" style="width:79%;margin-top:25px;">
					<?php 
					if ($_REQUEST[gid]=='') {
						if ($_REQUEST[shopid]!='') { ?>
						<select name="zixilie" class="select">
							<?php
							$query = mysql_query("select zileimu from shop where shopid=".$_REQUEST[shopid]);
							$shop = mysql_fetch_assoc($query);

							$query=mysql_query("select * from zifenlei where id in (".$shop['zileimu'].")");
							while ($row=mysql_fetch_array($query)) {
								?>
								<option value="<?php echo $row[id]; ?>">
									<?php echo $row[name]; ?>(<?php if ($row[type] == 0) { ?>海淘<?php }elseif ($row[type] == 1) { ?>快购<?php } ?>)
								</option>
								<?php } ?>
							</select>
							<?php }else{ ?>
							<select name="zixilie" class="zixilie">
								<?php
								$query=mysql_query("select * from zifenlei where fenleiid=(select leimu from shop limit 1)");
								while ($row = mysql_fetch_assoc($query)) {
								?>
								<option value="<?php echo $row[id]; ?>">
									<?php echo $row[name]; ?>(<?php if ($row[type] == 0) { ?>海淘<?php }elseif ($row[type] == 1) { ?>快购<?php } ?>)
								</option>
								<?php } ?>
							</select>
							<?php } }else{ 
								$query=mysql_query("select * from goods where goodsid='".$_REQUEST[gid]."'");
								$goods=mysql_fetch_array($query);
								if ($_REQUEST[shopid]!='') { ?>
								<select name="zixilie">
									<?php
									$query = mysql_query("select zileimu from shop where shopid=".$goods[shopid]);
									$shop = mysql_fetch_assoc($query);

									$query=mysql_query("select * from zifenlei where id in (".$shop['zileimu'].")");
									while ($row=mysql_fetch_array($query)) {
										?>
										<option value="<?php echo $row[id]; ?>" <?php if($goods[zixilie]==$row[id]){ ?> selected <?php } ?>>
											<?php echo $row[name]; ?>(<?php if ($row[type] == 0) { ?>海淘<?php }elseif ($row[type] == 1) { ?>快购<?php } ?>)
										</option>
										<?php } ?>
									</select>
									<?php }else{ 
										?>
										<select name="zixilie" class="zixilie">
											<?php 
											$query = mysql_query("select zileimu from shop where shopid=".$goods[shopid]);
											
											$shop = mysql_fetch_assoc($query);
											$query=mysql_query("select * from zifenlei where id in (".$shop['zileimu'].")");

											while ($row=mysql_fetch_array($query)){ ?>
											<option value="<?php echo $row[id]; ?>" <?php if($goods[zixilie]==$row[id]){ ?>selected<?php } ?>><?php echo $row[name]; ?>(<?php if ($row[type] == 0) { ?>海淘<?php }elseif ($row[type] == 1) { ?>快购<?php } ?>)
											</option>
											<?php } ?>
										</select>
										<?php } } ?>

									</div>

								</div>
								<!--子分类 end-->

								<!--配送时间-->
								<div class="car_mode delivery_time" <?php if ($hasDeliveryTime == 0) { ?> style="display:none;" <?php } ?>>


									<div class="indexfloat" style="width:15%; margin-left:5%;">
										配送时间
									</div> 


									<div class="indexfloat" style="width:79%;">

										<input class="text"  type="text" name="delivery_time" placeholder="配送时间" value="<?php echo $sdg30[delivery_time];?>"/> 

									</div>

								</div>
								<!--配送时间 end-->

								<!--收货信息-->
		<!-- 						<div class="car_mode">


									<div class="indexfloat" style="width:15%; margin-left:5%;">
										点赞数
									</div> 


									<div class="indexfloat" style="width:79%;">

										<input class="text"  type="text" name="xihuan" placeholder="喜欢数量" value="<?php echo $sdg30[xihuan];?>"/> 

									</div>

								</div> -->
								<!--收货信息 end-->


								<!--支持返券-->
								<div class="car_mode">

									<div class="indexfloat" style="width:15%; margin-left:5%;">
										支持返券
									</div> 


									<div class="indexfloat" style="width:79%;">
										<input type="radio" name="can_fanquan" value="1" <?php if ($sdg30[can_fanquan] == 1) { ?> checked="checked" <?php } ?> />是
										<input type="radio" name="can_fanquan" value="0" <?php if ($sdg30[can_fanquan] == 0) { ?> checked="checked" <?php } ?> />否


									</div>

								</div>
								<!--支持返券 end-->


								<!--收货信息-->
<!-- 								<div class="car_mode">

									<div class="indexfloat" style="width:15%; margin-left:5%;">
										数量
									</div>
									<div class="indexfloat" style="width:79%;">

										<?php if ($sdg30[number]!='') {echo $sdg30[number];}else{echo 0;} ;?><span style="color:#E63F00;margin-left:10px;">(数量由各种规格数量决定,此处无需编辑)</span>

										</div>
									</div> -->
									<!--收货信息 end-->					



</form>
<!--收货信息-->
<div class="car_mode">
	<div class="indexfloat" style="width:15%; margin-left:5%;">
		规格
	</div>
	<div class="indexfloat" style="width:79%;">
	    <ul id="class">
	    <?php foreach ($data as $v) { ?>
	        <li>
	            名字:
	            <input type="text" value="<?php echo $v[name]; ?>">
	            <span <?php if (!empty($v[classs])) { ?>
	            style="display:none;" <?php } ?>>
			    
			    <?php if($_SESSION['type'] == 0) {?>
				价格:<input type="text" value="
		            <?php 
		            if (!empty($v[price])) {
		            	echo $v[price];
		            } 
		            ?>">
		        <?php } else {?>
					价格:<input type="text"  readonly="disabled" onclick="tanchu()" value="
			            <?php 
			            if (!empty($v[price])) {
			            	echo $v[price];
			            } 
			            ?>">
			    <?php }?>

			    数量：
			    <input type="text" value="
	            <?php 
	            if (!empty($v[num])) {
	            	echo $v[num];
	            } 
	            ?>">
		       	</span>
	            <button onclick="ad_class(this)">添加子类</button>
	            <button onclick="remove_min_class(this)">删除</button>
	            <ul>
	            	<?php foreach ($v[classs] as $value) { ?>
					<li >
					
					子类:<input type="text" value="<?php echo $value[name]; ?>">
					<?php if($_SESSION['type'] == 0) {?>
						价格:<input type="text" value="<?php echo $value[price]; ?>"> 
					<?php } else {?>
						价格:<input type="text" readonly="disabled" onclick="tanchu()" value="<?php echo $value[price]; ?>"> 
					<?php } ?>
					数量:<input type="text" value="<?php echo $value[num]; ?>">
					<button onclick="remove_class(this)">删除</button>
					</li>
					<?php } ?>
	            </ul>
	        </li>
		<?php } ?>
	    </ul>

	    <div class="class_html" style="display: none ;">

	        <li id="min-class">
	            名字:<input type="text">
	            <span>
			    价格:<input type="text">
			    数量：<input type="text" >
		       	</span>
	            <button>添加子类</button>
	            <button onclick="remove_min_class(this)">删除</button>
	            <ul></ul>
	        </li>
	        <li id="m-class">
	            子类:
	            <input type="text"> 价格:
	            <input type="text"> 数量:
	            <input type="text">
	            <button onclick="remove_class(this)">删除</button>
	        </li>
	        <input type="hidden" id="goodsid" value="<?php echo $_GET[gid]; ?>">
	    </div>
	    <button onclick="add_main_class()">添加</button>
	</div>
</div>
<!--收货信息 end-->	
</div>
<div class="submit_div">		
	<input name="" type="submit" value="提交" onclick="class_submits();" id="submit" />
</div>
</body>
</html>

<script type="text/javascript">
	// 表单验证
	$().ready(function() {
		$("#form").validate();
	});
	// 表单验证 end
	function zi(n)
	{
		for(var i=1;i<=30;i++)
		{
			document.getElementById(i).style.display="none"; 
			document.getElementById(n).style.display="block";  
		}

	}

</script>
<script type="text/javascript">
	function tanchu() {
		alert('您没有权限修改价格')
	}

	function shop(m)   
	{
		for(var j=31;j<=60;j++)
		{
			document.getElementById(j).style.display="none"; 
			document.getElementById(m).style.display="block";  
		}
	}


	var shopid=$('.shopid');
	var gid=$('#gid');
	shopid.change(function(){
		$('.zixilie').empty();
		$('#fare').empty();
		var shopidval=shopid.val();
		var gidval=gid.val();
		var url='addgoods.php?act=selectcat&shopid='+shopidval+'&gid='+gidval;
		
		$.get(url,function(data){

			var infos = JSON.parse(data);
			var cats = infos.cats;
			var fare = infos.fare;
			for(var i=0;i<cats.length;i++){
				$('.zixilie').append("<option  value='"+cats[i].id+"'>"+cats[i].name+"</option>")
			};
			for(var i=0;i<fare.length;i++){
				$('#fare').append("<option  value='"+fare[i].id+"'>"+fare[i].name+"</option>")
			};

		});

		var preurl = 'addgoods.php?act=getGuige&shopid='+shopidval;
		$('#class').empty();
		$.get(preurl,function(data){
			var infos = JSON.parse(data);
			var html="";
			for (i in infos) {
				html+='<li>名字:<input type="text" value="'+infos[i].name+'"><span ';
				if(infos[i].classs[0]){
                   html+='style="display:none;"';
				}
				html+='>价格:<input type="text" value="';
				if (infos[i].price) {
					html+=''+infos[i].price+'';
				}
				html+='">数量:<input type="text" value="';
				if (infos[i].num) {
					html+=''+infos[i].num+'';
				}
				html+='"></span><button onclick="ad_class(this)">添加子类</button><button onclick="remove_min_class(this)">删除</button><ul>';
				for(x in infos[i].classs){
					html+='<li>子类:<input type="text" value="'+infos[i].classs[x].name+'">价格:<input type="text" value="'+infos[i].classs[x].price+'">数量:<input type="text" value="'+infos[i].classs[x].num+'"><button onclick="remove_class(this)">删除</button></li>';
				}
				html+='</ul></li>';
			}
			$('#class').append(html);

		});

	});
	// 提交表单
	
	$('#submit').click(function(){
		// editor.sync(); 
		$('#form').submit();
	})
	// 提交表单 end

	// 根据子分类查询子分类类型(海淘或快购),若为快购,需要设置配送时间
	$('select[name="zixilie"]').change(function(){
		var zixilie = $(this).val();
		var url = 'addgoods.php?act=getType&zixilie='+zixilie;
		$.get(url,function(data){
			if (data == 1) {
				$('.delivery_time').show();
			}else{
				$('.delivery_time').hide();
			};
			var preurl = 'addgoods.php?act=getGuige&zixilie='+zixilie;
			$('#class').empty();
			$.get(preurl,function(data){
				var infos = JSON.parse(data);
				var html="";
				for (i in infos) {
					html+='<li>名字:<input type="text" value="'+infos[i].name+'"><span ';
					if(infos[i].classs[0]){
                       html+='style="display:none;"';
					}
					html+='>价格:<input type="text" value="';
					if (infos[i].price) {
						html+=''+infos[i].price+'';
					}
					html+='">数量:<input type="text" value="';
					if (infos[i].num) {
						html+=''+infos[i].num+'';
					}
					html+='"></span><button onclick="ad_class(this)">添加子类</button><button onclick="remove_min_class(this)">删除</button><ul>';
					for(x in infos[i].classs){
						html+='<li>子类:<input type="text" value="'+infos[i].classs[x].name+'">价格:<input type="text" value="'+infos[i].classs[x].price+'">数量:<input type="text" value="'+infos[i].classs[x].num+'"><button onclick="remove_class(this)">删除</button></li>';
					}
					html+='</ul></li>';
				}
				$('#class').append(html);

			});
		})
	})
	// 根据子分类查询子分类类型(海淘或快购),若为快购,需要设置配送时间 end
	// 根据商家查询子分类类型(海淘或快购),若为快购,需要设置配送时间
	$('select[name="shopid"]').change(function(){
		var shopid = $(this).val();
		var url = 'addgoods.php?act=getType&shopid='+shopid;
		$.get(url,function(data){
			if (data == 1) {
				$('.delivery_time').show();
			}else{
				$('.delivery_time').hide();
			};
		})
	})
	// 根据商家查询子分类类型(海淘或快购),若为快购,需要设置配送时间


</script>